import { CmdSignModel, CustomerModel } from '../models/index';
import { NetService } from './net.service';
import Taro from '@tarojs/taro';
import { cacheService } from '.';
declare let SERVER_URL: string;
class HttpService extends NetService {
  private static _instance: HttpService;

  private constructor() {
    super();
  }

  public static get Instance() {
    return this._instance || (this._instance = new this());
  }

  sendData(cmdSign: CmdSignModel): Promise<any> {
    let userInfo: CustomerModel = cacheService.getSession();
    let header: any = {};
    if (userInfo) {
      if (userInfo.isCanary == undefined) {
        header.canary = 1;
      } else {
        header.canary = userInfo.isCanary;
      }
    }
    // header.canary = 1;
    let cmdData
    if (Taro.getEnv() == Taro.ENV_TYPE.WEB) {
      cmdData = JSON.stringify(cmdSign)
    } else {
      cmdData = cmdSign
    };
    return Taro.request({
      header: header,
      url: `${SERVER_URL}/store/api`,
      method: 'POST',
      data: cmdData
    });
  }
}

const instance = HttpService.Instance;
export default instance;